#include <bits/stdc++.h>
using namespace std;

int main() {
	freopen("family.in", "r", stdin);
	int N;
	vector<string> cows(2);
	cin >> N >> cows[0] >> cows[1];

	map<string, string> edge;
	for (int i = 0; i < N; ++i) {
		string u, v;
		cin >> v >> u;
		// If v is a mother of u, then there is an edge from node u to node v.
		edge[u] = v;
	}

	// Map of the ancestors of each node & their distances
	vector<map<string, int>> ancestors(2);
	for (int c = 0; c < 2; c++) {
		// BFS to find the ancestors of both cows and the distance to them
		string at = cows[c];
		ancestors[c][cows[c]] = 0;
		while (edge.count(at) != 0) {
			auto n = edge.find(at);
			ancestors[c][n->second] = ancestors[c][at] + 1;
			at = n->second;
		}
	}

	string common;
	int dist0 = INT32_MAX;  // distance from cow 0 to the common ancestor
	int dist1 = INT32_MAX;  // and the distance from cow 1
	// Finding the lowest common ancestor
	for (const pair<string, int> &d0 : ancestors[0]) {
		auto d1 = ancestors[1].find(d0.first);
		if (d1 != ancestors[1].end() && (dist0 > d0.second || dist1 > d1->second)) {
			common = d0.first;
			dist0 = d0.second;
			dist1 = d1->second;
		}
	}

	freopen("family.out", "w", stdout);

	if (common.empty()) {
		cout << "NOT RELATED";
	} else if (common == cows[1] || common == cows[0]) {
		if (common == cows[0]) {
			swap(cows[0], cows[1]);
			swap(dist0, dist1);
		}
		cout << cows[1] << " is the ";
		if (dist0 >= 2) {
			for (int i = 0; i < dist0 - 2; ++i) { cout << "great-"; }
			cout << "grand-";
		}
		cout << "mother of " << cows[0];
	} else {
		if (dist1 < dist0) {
			swap(dist1, dist0);
			swap(cows[1], cows[0]);
		}
		if (dist0 == 1) {
			if (dist1 == 1) {
				cout << "SIBLINGS";
			} else {
				cout << cows[0] << " is the ";
				for (int i = 0; i < dist1 - 2; ++i) { cout << "great-"; }
				cout << "aunt of " << cows[1];
			}
		} else {
			cout << "COUSINS";
		}
	}
	cout << endl;
}

/*
// Passes most test cases, but not all:
#include <bits/stdc++.h>

using namespace std;

int n, p = -1, q = -1;
int tree[101], t1[101];
string x, y;
unordered_map<string,int> name;
unordered_set<int> t;

int help() {
    // If we never found a common ancestor
    if (p == -1 || q == -1) return 6;
    
    if (p == 0) return 0;
    if (q == 0) return 1;
    if (p == 1 && q == 1) return 2;
    if (p == 1 && q > 1) return 3;
    if (p > 1 && q == 1) return 4;
    if (p > 1 && q > 1) return 5;
    return 6;
}

int main() {
    freopen("family.in", "r", stdin);
    cin >> n >> x >> y;

    int cnt = 1;
    for (int i = 1; i <= n; i++) {
        string a, b;
        cin >> a >> b;
        if (!name[a]) name[a] = cnt++;
        if (!name[b]) name[b] = cnt++;
        tree[name[b]] = name[a];
    }

    // Store ancestors of x
    {
        int idx = name[x];
        int c = 0;
        while (tree[idx]) {
            idx = tree[idx];
            t1[c++] = idx;
            t.insert(idx);
        }
    }

    // Find common ancestor with y
    {
        int idx = name[y];
        int c = 0;
        while (tree[idx]) {
            idx = tree[idx];
            c++;
            if (t.count(idx)) {
                p = c;            // Distance from y to common ancestor
                int pos = 0;
                while (t1[pos] != idx) pos++;
                q = pos + 1;      // Distance from x to common ancestor
                break;
            }
        }
    }

    freopen("family.out", "w", stdout);
    switch (help()) {
    case 0:
        cout << x << " is the ";
        while (q > 3) { cout << "great-"; q--; }
        if (q == 3) cout << "great-great-"; 
        else if (q == 2) cout << "grand-";
        cout << "mother of " << y << "\n";
        break;
    case 1:
        cout << y << " is the ";
        while (p > 3) { cout << "great-"; p--; }
        if (p == 3) cout << "great-great-";
        else if (p == 2) cout << "grand-";
        cout << "mother of " << x << "\n";
        break;
    case 2:
        cout << "SIBLINGS\n";
        break;
    case 3:
        cout << y << " is the ";
        for (int i = 0; i < q - 2; i++) cout << "great-";
        cout << "aunt of " << x << "\n";
        break;
    case 4:
        cout << x << " is the ";
        for (int i = 0; i < p - 2; i++) cout << "great-";
        cout << "aunt of " << y << "\n";
        break;
    case 5:
        cout << "COUSINS\n";
        break;
    case 6:
        cout << "NOT RELATED\n";
        break;
    }

    return 0;
}
*/